<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 示例：
var person = {
  "name": "小明",
  "info": {
     "age": "18",
     "address": {
       "country": "中国",
       "province": "广东",
     }
  }
}

输出：
name = 小明
info.age = 18
info.address.country = 中国
info.address.province = 广东
输出：
name = 小明
info.age = 18
info.address.country = 中国
info.address.province = 广东
     -->
    <script>
      let person = {
        name: "小明",
        info: {
          age: "18",
          address: {
            country: "中国",
            province: "广东",
          },
        },
      };

      const fn = (person, rpre = "person") => {
        let cur = "";
        let pre = rpre;
        if (person.constructor === Object) {
          for (let key in person) {
            cur = key;
            if (person[key].constructor === Object) {
              pre = pre + "." + key;
              fn(person[key], pre);
            } else {
              console.log(`${pre === "" ? "" : `${pre}.`}` + cur + "=" + person[key]);
            }
          }
        } else {
          for (let key in person) {
            cur = key;
            console.log(`${pre === "" ? "" : `${pre}.`}` + cur + "=" + person[key]);
          }
        }
      };
      fn(person);
    </script>
  </body>
</html>
